﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicaNegocios.Manager;
using Dominio;

namespace UIWeb
{
    public partial class ReporteLogUsuario : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UsuarioManager um = UsuarioManager.GetManager();
            if (Session["userLogin"] == null)
            {
                Response.Redirect("~/UserLogin.aspx");
            }
            else
            {
                if (um.esSeguidor((Usuario)Session["userLogin"]) || um.noTieneRol((Usuario)Session["userLogin"]))
                    if (um.esAdmin((Usuario)Session["userLogin"]))
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                    else
                        Response.Redirect("~/Default_seguidores.aspx");
                else
                {
                    if (!IsPostBack)
                    {
                        txtIniDate.Text = String.Format("{0:dd/MM/yyyy}", DateTime.Now.AddDays(-1));
                        txtEndDate.Text = String.Format("{0:dd/MM/yyyy}", DateTime.Now);
                    }
                }
            }
        }

        protected void lnkSearch_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            string[] dateIniAux = txtIniDate.Text.Split('/');
            DateTime dateIni = new DateTime(Convert.ToInt32(dateIniAux[2]), Convert.ToInt32(dateIniAux[1]), Convert.ToInt32(dateIniAux[0]), 0, 0, 0);

            string[] dateEndAux = txtEndDate.Text.Split('/');
            DateTime dateEnd = new DateTime(Convert.ToInt32(dateEndAux[2]), Convert.ToInt32(dateEndAux[1]), Convert.ToInt32(dateEndAux[0]), 0, 0, 0);

            ReporteManager reporteMgr = ReporteManager.GetManager();
            List<contentDataLog> list = reporteMgr.logEntradaUsuarios(dateIni, dateEnd, this.Context.Server.MapPath("~\\"));

            if (list.Count > 0)
            {
                GDVLog.DataSource = list;
                GDVLog.DataBind();
            }
            else
            {
                lblError.Text = "No existen datos para el periodo seleccionado";
            }



        }
    }
}